#include "framelesswidget.h"

FramelessWidget::FramelessWidget(QWidget *parent,int y_num)
    : QMainWindow(parent),
      dragging(false),
      y_num(y_num)
{
    setWindowFlags(Qt::Window | Qt::CustomizeWindowHint);
}
void FramelessWidget::mousePressEvent(QMouseEvent *event) {
    if (event->button() == Qt::LeftButton && event->pos().y() <= y_num) {
        dragging = true;
        dragPosition = event->globalPos() - frameGeometry().topLeft();
        event->accept();
    }
}

void FramelessWidget::mouseMoveEvent(QMouseEvent *event) {
    if (dragging && (event->buttons() & Qt::LeftButton)) {
        move(event->globalPos() - dragPosition);
        event->accept();
    }
}

void FramelessWidget::mouseReleaseEvent(QMouseEvent *event) {
    if (event->button() == Qt::LeftButton) {
        dragging = false;
        event->accept();
    }
}
